<?php
/**
 *
 * User: Robin
 * Date: 2019/11/12 0012
 * Email: 704289189@qq.com
 **/


namespace app\admin\model\system;


use app\common\model\BaseModel;

/**
 * Class Role  身份管理模型
 * @package app\admin\model\system
 */
class Role extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';
    /**
     * 模型名称
     * @var string
     */
    protected $name = 'role';

    public static function setRulesAttr($value){
        return is_array($value)? implode(',',$value) : $value;
    }

    /**
     * 选择管理员身份
     * @param int $level
     * @return array
     */
    public static function getRole($level = 0){
        return self::where('status',1)->where('level',$level)->column('role_name','id');
    }

    public static function rolesByAuth($rules){
        if (empty($rules)) return [];
        $rules = self::where('id','IN',$rules)->where('status',1)->column('rules','id');
        $rules = array_unique(explode(',',implode(',',$rules)));
        $_auth =  '权限设置' ;
    }
}